clear all 
set more off

cd "C:\Dropbox\Average_target_survey\replication_folder\rawdata"

import excel using "dataset_2021_08_17_onward_for_STATA.xlsx", sheet("Sheet1") cellrange("A1") firstrow clear

*===============================================================================
*				destring variables
*===============================================================================
quiet foreach var in Q2 Q3 Q48 Q49 Q124 Q51 Q52 Q1341 QA11 Q111 Q151 ///
	QJH2 QJH3 QJH4 QJH6 QJH13 QJH14 QJH15 QJH16 ///
	Q27 Q53 Q121 FL_5_DO ///
	QJH1_DO QJH5_DO QJH8_DO QJH9_DO  ///
	JH12 ///
	FL_46_DO	FL_7_DO	FL_8_DO	FL_9_DO	FL_10_DO	FL_11_DO  {
		noisily di "`var'"
		gen `var'x=`var'
		encode `var', gen(`var'N)
		drop `var'
		rename `var'N `var'
	}
	
	
	
*** zipcode	
destring Q50, force replace

*** fix labels for how many times people heard about the Fed	
label define many_news ///
	1 "Just one" ///
	2 "2" ///
	3 "3 to 5" ///
	4 "5+" ///
	5 "I don't remember" 

recode QJH4 1=5 2=1 3=4 4=3  5=2
label values QJH4 	many_news

						 
*** fix labels for when people heard the newspapers
label define when_hear ///
	0 "In the last couple of hours" ///
	1 "Earlier today" ///
	2 "Yesterday" ///
	3 "Two days ago" ///
	4 "Three days ago" ///
	5 "More than three days ago" ///
	6 "I don't remember"
recode QJH6 3=0  7=2 6=3 5=4 4=5 2=6
label values QJH6 	when_hear
	
*** fix labels for when people think mortgage rates will increase 
label define when_mrt ///
	0 "Second half 2021" ///
	1 "Sometime in 2022" ///
	2 "Sometime in 2023" ///
	3 "In 2024 or later" ///
	4 "They are unlikely to rise" ///
	99 "Not sure"
recode QJH16 2=99 3=0 4=1 5=2 1=3 6=4 
label values QJH16 when_mrt					   
							 
							 
*** fix labels for income
label define inc_bin ///
	0 "Less than $10,000" ///
	1 "$10,000 - $19,999" ///
	2 "$20,000 - $34,999" ///
	3 "$35,000 - $49,999" ///
	4 "$50,000 - $99,999" ///
	5 "$100,000 - $199,999" ///
	6 "More than $200,000" 
recode Q49 6=0 1=1 3=2 4=3 5=4 2=5 7=6
label values Q49 inc_bin	
	   

*** fix labels for education (make sequential)
label define inc_edu ///
	1 "Less than high school" ///
	2 "High school diploma or equivalent" ///
	3 "Some college, but no degree" ///
	4 "Bachelor's degree" ///
	5 "Master's degree" ///
	6 "Doctorate or Professional Degree" 
recode Q48 1=4 2=6 3=2 4=1 5=5 6=3
label values Q48 inc_edu	  
					 
*===============================================================================
*				code variables with multiple options allowed
*===============================================================================

* QJH1

gen QJH1_1=0 if QJH1~=""
replace QJH1_1=1 if strpos(QJH1,"Articles in either general-interest newspapers or specialized economics and finance newspapers")~=0 & QJH1~="" 

gen QJH1_2=0 if QJH1~=""
replace QJH1_2=1 if strpos(QJH1,"online or in print (like the USA Today, New York Times, Wall Street Journal, Economist)")~=0 & QJH1~="" 

gen QJH1_3=0 if QJH1~=""
replace QJH1_3=1 if strpos(QJH1,"Twitter, Facebook, or other social media")~=0 & QJH1~="" 

gen QJH1_4=0 if QJH1~=""
replace QJH1_4=1 if strpos(QJH1,"News or other programs on television and radio")~=0 & QJH1~="" 

gen QJH1_5=0 if QJH1~=""
replace QJH1_5=1 if strpos(QJH1,"Other internet sources (blogs, discussion forums)")~=0 & QJH1~="" 

gen QJH1_6=0 if QJH1~=""
replace QJH1_6=1 if strpos(QJH1,"Coworkers")~=0 & QJH1~="" 

gen QJH1_7=0 if QJH1~=""
replace QJH1_7=1 if strpos(QJH1,"Friends and relatives")~=0 & QJH1~="" 

gen QJH1_8=0 if QJH1~=""
replace QJH1_8=1 if strpos(QJH1,"I did not come across any information on economic and business conditions")~=0 & QJH1~="" 

gen QJH1_9=0 if QJH1~=""
replace QJH1_9=1 if strpos(QJH1,"Official sources (like the web pages of the government, statistical agencies, or the Federal Reserve Banks)")~=0 & QJH1~="" 

*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

* QJH5

gen QJH5_1=0 if QJH5~=""
replace QJH5_1=1 if strpos(QJH5,"Articles in either general-interest newspapers or specialized economics and finance newspapers")~=0 & QJH5~="" 
label var QJH5_1 "Heard about Fed from: Articles in either general-interest"

gen QJH5_2=0 if QJH5~=""
replace QJH5_2=1 if strpos(QJH5,"online or in print (like the USA Today, New York Times, Wall Street Journal, Economist)")~=0 & QJH5~="" 
label var QJH5_2 "Heard about Fed from: online or in print"

gen QJH5_3=0 if QJH5~=""
replace QJH5_3=1 if strpos(QJH5,"Twitter, Facebook, or other social media")~=0 & QJH5~="" 
label var QJH5_3 "Heard about Fed from: Twitter, Facebook"

gen QJH5_4=0 if QJH5~=""
replace QJH5_4=1 if strpos(QJH5,"News or other programs on television and radio")~=0 & QJH5~="" 
label var QJH5_4 "Heard about Fed from: News or other programs on television and radio"

gen QJH5_5=0 if QJH5~=""
replace QJH5_5=1 if strpos(QJH5,"Other internet sources (blogs, discussion forums)")~=0 & QJH5~="" 
label var QJH5_5 "Heard about Fed from: Other internet sources"

gen QJH5_6=0 if QJH5~=""
replace QJH5_6=1 if strpos(QJH5,"Coworkers")~=0 & QJH5~="" 
label var QJH5_6 "Heard about Fed from: Coworkers"

gen QJH5_7=0 if QJH5~=""
replace QJH5_7=1 if strpos(QJH5,"Friends and relatives")~=0 & QJH5~="" 
label var QJH5_7 "Heard about Fed from: Friends and relatives"

gen QJH5_8=0 if QJH5~=""
replace QJH5_8=1 if strpos(QJH5,"I did not come across any information on economic and business conditions")~=0 & QJH5~="" 
label var QJH5_8 "Heard about Fed from: I did not come across"

gen QJH5_9=0 if QJH5~=""
replace QJH5_9=1 if strpos(QJH5,"Official sources (like the web pages of the government, statistical agencies, or the Federal Reserve Banks)")~=0 & QJH5~="" 
label var QJH5_9 "Heard about Fed from: Official sources"
	
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

* QJH8

gen QJH8_1=0 if QJH8~=""
replace QJH8_1=1 if strpos(QJH8,"Jerome Powell")~=0 & QJH8~="" 
label var QJH8_1 "Heard about Fed from: Jerome Powell"

gen QJH8_2=0 if QJH8~=""
replace QJH8_2=1 if strpos(QJH8,"Christine Lagarde")~=0 & QJH8~="" 
label var QJH8_2 "Heard about Fed from: Christine Lagarde"

gen QJH8_3=0 if QJH8~=""
replace QJH8_3=1 if strpos(QJH8,"Alan Greenspan")~=0 & QJH8~="" 
label var QJH8_3 "Heard about Fed from: Alan Greenspan"

gen QJH8_4=0 if QJH8~=""
replace QJH8_4=1 if strpos(QJH8,"Janet Yellen")~=0 & QJH8~="" 
label var QJH8_4 "Heard about Fed from: Janet Yellen"

gen QJH8_5=0 if QJH8~=""
replace QJH8_5=1 if strpos(QJH8,"None of the above")~=0 & QJH8~="" 
label var QJH8_5 "Heard about Fed from: None of the above"

gen QJH8_6=0 if QJH8~=""
replace QJH8_6=1 if strpos(QJH8,"remember")~=0 & QJH8~="" 
label var QJH8_6 "Heard about Fed from: I don’t remember their names"

*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

* QJH9

gen QJH9_1=0 if QJH9~=""
replace QJH9_1=1 if strpos(QJH9,"Keeping interest rates low to reduce the government")~=0 & QJH9~="" 
label var QJH9_1 "Fed objective: Keeping interest rates low to reduce the government’s cost of borrowing"

gen QJH9_2=0 if QJH9~=""
replace QJH9_2=1 if strpos(QJH9,"Promoting maximum employment")~=0 & QJH9~="" 
label var QJH9_2 "Fed objective: Promoting maximum employment"

gen QJH9_3=0 if QJH9~=""
replace QJH9_3=1 if strpos(QJH9,"Keeping stock prices high")~=0 & QJH9~="" 
label var QJH9_3 "Fed objective: Keeping stock prices high"

gen QJH9_4=0 if QJH9~=""
replace QJH9_4=1 if strpos(QJH9,"Bailing out failing financial institutions")~=0 & QJH9~="" 
label var QJH9_4 "Fed objective: Bailing out failing financial institutions"

gen QJH9_5=0 if QJH9~=""
replace QJH9_5=1 if strpos(QJH9,"Ensuring price stability")~=0 & QJH9~="" 
label var QJH9_5 "Fed objective: Ensuring price stability"

gen QJH9_6=0 if QJH9~=""
replace QJH9_6=1 if strpos(QJH9,"Maintaining a strong dollar")~=0 & QJH9~="" 
label var QJH9_6 "Fed objective: Maintaining a strong dollar"

gen QJH9_7=0 if QJH9~=""
replace QJH9_7=1 if strpos(QJH9,"Reducing economic inequality")~=0 & QJH9~="" 
label var QJH9_7 "Fed objective: Reducing economic inequality"

gen QJH9_8=0 if QJH9~=""
replace QJH9_8=1 if strpos(QJH9,"Fighting climate change")~=0 & QJH9~="" 
label var QJH9_8 "Fed objective: Fighting climate change"

gen QJH9_9=0 if QJH9~=""
replace QJH9_9=1 if strpos(QJH9,"Mitigating the economic consequences of racism")~=0 & QJH9~="" 
label var QJH9_9 "Fed objective: Mitigating the economic consequences of racism"

*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

* QJH10

gen QJH10_1=0 if QJH10~=""
replace QJH10_1=1 if strpos(QJH10,"Keep the inflation rate as close as possible to a specific target at all times")~=0 & QJH10~="" 
label var QJH10_1 "Fed objective: Keep the inflation rate as close as possible to a specific target at all times"

gen QJH10_2=0 if QJH10~=""
replace QJH10_2=1 if strpos(QJH10,"Make inflation, on average, be approximately equal to a target rate")~=0 & QJH10~="" 
label var QJH10_2 "Fed objective: Make inflation, on average, be approximately equal to a target rate"

gen QJH10_3=0 if QJH10~=""
replace QJH10_3=1 if strpos(QJH10,"Keep prices from rising over time")~=0 & QJH10~="" 
label var QJH10_3 "Fed objective: Keep prices from rising over time"

gen QJH10_4=0 if QJH10~=""
replace QJH10_4=1 if strpos(QJH10,"Ensure inflation is sufficiently high to erode the value of government debt")~=0 & QJH10~="" 
label var QJH10_4 "Fed objective: Ensure inflation is sufficiently high to erode the value of government debt"

gen QJH10_5=0 if QJH10~=""
replace QJH10_5=1 if strpos(QJH10,"Keep the inflation rate low enough to promote a strong dollar")~=0 & QJH10~="" 
label var QJH10_5 "Fed objective: Keep the inflation rate low enough to promote a strong dollar"

gen QJH10_6=0 if QJH10~=""
replace QJH10_6=1 if strpos(QJH10,"None of the above")~=0 & QJH10~="" 
label var QJH10_6 "Fed objective: None of the above"

gen QJH10_7=0 if QJH10~=""
replace QJH10_7=1 if strpos(QJH10,"know")~=0 & QJH10~="" 
label var QJH10_7 "Fed objective: I don’t know"

*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

* QJH7_DO
gen QJH7=QJH7a
gen QJH7_1=0 if QJH7~=""
replace QJH7_1=1 if strpos(QJH7,"There was an international meeting of central bankers")~=0 & QJH7~="" 
label var QJH7_1 "What heard about the Fed: There was an international meeting of central bankers"

gen QJH7_2=0 if QJH7~=""
replace QJH7_2=1 if strpos(QJH7,"There was a change in interest rates announced")~=0 & QJH7~="" 
label var QJH7_2 "What heard about the Fed: There was a change in interest rates announced "

gen QJH7_3=0 if QJH7~=""
replace QJH7_3=1 if strpos(QJH7,"There was a change in the leadership at the Federal Reserve")~=0 & QJH7~="" 
label var QJH7_3 "What heard about the Fed: There was a change in the leadership at the Federal Reserve"

gen QJH7_4=0 if QJH7~=""
replace QJH7_4=1 if strpos(QJH7,"There was an announcement about new strategies at the Federal Reserve")~=0 & QJH7~="" 
label var QJH7_4 "What heard about the Fed: There was an announcement about new strategies at the Federal Reserve"

gen QJH7_5=0 if QJH7~=""
replace QJH7_5=1 if strpos(QJH7,"The Federal Reserve put in place new lending facilities to fight the recession")~=0 & QJH7~="" 
label var QJH7_5 "What heard about the Fed: The Federal Reserve put in place new lending facilities to fight the recession"

gen QJH7_6=0 if QJH7~=""
replace QJH7_6=1 if strpos(QJH7,"remember")~=0 & QJH7~="" 
label var QJH7_6 "What heard about the Fed: I don’t remember"




*===============================================================================
*		label variables
*===============================================================================

label var StartDate "Start Date"
label var EndDate "End Date"
label var Durationinseconds "Duration (in seconds)"
label var LocationLatitude "Location Latitude"
label var LocationLongitude "Location Longitude"

label var Q1 "Please enter your age:"
label var Q2 "What is your level of English?"
label var Q3 "Please indicate your gender."
label var Q48 "What is the highest level of school you have completed, or the highest degree you have achieved?"
label var Q49 "Please indicate the range of your yearly net disposable income"
label var Q50 "What is the postal (zip) code for the address of your permanent residence?"

label var Q124 "50 States, D.C. and Puerto Rico"
label var Q51 "How would you identify your ethnicity? Please select all that apply."
label var Q52 "Do you consider yourself of Hispanic, Latino or Spanish origin?"

label var Q1341 "Over the next 12 months, do you think that there will be an increase or decrease in GDP?"
label var Q1342I "What do you expect the rate of increase in GDP to be over the next 12 months? I expect the rate of increase to be ___ percent over the next 12 months."
label var Q1342D "What do you expect the rate of decrease in GDP to be over the next 12 months? I expect the rate of decrease to be ___ percent over the next 12 months."

label var QA11 "In your view, will the total income of all members of your household (including you), after taxes and deductions, increase or decrease over the next 12 months?"
label var QA12I "By how much do you expect total income of all members of your household to increase over the next 12 months? Over the next 12 months, I expect total income of all members of my household to increase by ___ percent."
label var QA12D "By how much do you expect total income of all members of your household to decrease over the next 12 months? Over the next 12 months, I expect total income of all members of my household to decrease by ___ percent."

label var Q111 "The next few questions are about inflation. Over the next 12 months, do you think that there will be inflation or deflation?"
label var Q112I "What do you expect the rate of inflation to be over the next 12 months? I expect the rate of inflation to be ___ percent over the next 12 months."
label var Q112D "What do you expect the rate of deflation to be over the next 12 months? I expect the rate of deflation to be ___ percent over the next 12 months."


label var Q13_1 "What would you say is the percent chance that, over the next 12 months. . . - the rate of inflation will be 12% or higher"
label var Q13_2 "What would you say is the percent chance that, over the next 12 months. . . - the rate of inflation will be between 8% and 12%"
label var Q13_3 "What would you say is the percent chance that, over the next 12 months. . . - the rate of inflation will be between 4% and 8%"
label var Q13_4 "What would you say is the percent chance that, over the next 12 months. . . - the rate of inflation will be between 2% and 4%"
label var Q13_5 "What would you say is the percent chance that, over the next 12 months. . . - the rate of inflation will be between 0% and 2%"
label var Q13_6 "What would you say is the percent chance that, over the next 12 months. . . - the rate of deflation (opposite of inflation) will be between 0% and 2%"
label var Q13_7 "What would you say is the percent chance that, over the next 12 months. . . - the rate of deflation (opposite of inflation) will be between 2% and 4%"
label var Q13_8 "What would you say is the percent chance that, over the next 12 months. . . - the rate of deflation (opposite of inflation) will be between 4% and 8%"
label var Q13_9 "What would you say is the percent chance that, over the next 12 months. . . - the rate of deflation (opposite of inflation) will be between 8% and 12%"
label var Q13_10 "What would you say is the percent chance that, over the next 12 months. . . - the rate of deflation (opposite of inflation) will be 12% or higher"


label var Q151 "Now we would like you to think about inflation further into the future. Over the 12-month period between September 2022 and September 2023 do you think that there will be inflation or deflation?"
label var Q152I "What do you expect the rate of inflation to be over the 12-month period between September 2022 and September 2023? I expect the rate of inflation to be ___ percent."
label var Q152D "What do you expect the rate of deflation to be over the 12-month period between September 2022 and September 2023? I expect the rate of deflation to be ___ percent."

label var QJH1 "How do you usually get news about the economy?  Select all that apply. - Selected Choice"
label var QJH1_10_TEXT "How do you usually get news about the economy?  Select all that apply. - Another source: - Text"
label var QJH1_DO "How do you usually get news about the economy?  Select all that apply. - Display Order"

label var QJH2 "How often do you get news about the economy? - Selected Choice"
label var QJH2_8_TEXT "How often do you get news about the economy? - Other: - Text"

label var QJH3 "Have you heard any news about monetary policy or the Federal Reserve in the last week?"
label var QJH4 "About how many news articles, TV or radio reports, or other pieces of news about monetary policy or the Federal Reserve did you read or hear in the last week?"

label var QJH5 "Where did you hear this news about monetary policy or the Federal Reserve?  Select all that apply. - Selected Choice"
label var QJH5_9_TEXT "Where did you hear this news about monetary policy or the Federal Reserve? Select all that apply. - Another source: - Text"
label var QJH5_DO "Where did you hear this news about monetary policy or the Federal Reserve?  Select all that apply. - Display Order"

label var QJH6 "When did you hear the most recent news about monetary policy or the Federal Reserve? Please select the most appropriate answer."

label var QJH7 "What were the main pieces of news about monetary policy or the Federal Reserve that you heard most recently?  Select all that apply. - Selected Choice"
label var QJH7a_7_TEXT "What were the main pieces of news about monetary policy or the Federal Reserve that you heard most recently?  Select all that apply. - Other: - Text"
label var QJH7a_DO "What were the main pieces of news about monetary policy or the Federal Reserve that you heard most recently?  Select all that apply. - Display Order"

label var QJH8 "Who did you hear news about? Select all that apply."
label var QJH8_DO "Who did you hear news about? Select all that apply. - Display Order"

label var QJH9 "In terms of the Federal Reserves broad economic objectives, what do you think it views as most important among the following?  Please select up to 2."
label var QJH9_DO "In terms of the Federal Reserves broad economic objectives, what do you think it views as most important among the following?  Please select up to 2. - Display Order"

label var QJH10 "In terms of prices in the economy, which do you think best represents what the Federal Reserve is trying to do?  Select all that apply."
label var QJH10_DO "In terms of prices in the economy, which do you think best represents what the Federal Reserve is trying to do?  Select all that apply. - Display Order"

label var QJH11 "What rate of inflation do you think the Federal Reserve tries to achieve in the longer run?______% per year"

label var QJH123 "Suppose that the inflation rate in 2022 turns out to be around 1%. What inflation rate do you think the Federal Reserve will try to achieve over the following year or two?_____ % per year"
label var QJH124 "Suppose that the inflation rate in 2022 turns out to be around 3%. What inflation rate do you think the Federal Reserve will try to achieve over the following year or two?_____ % per year"

label var QJH13 "Over the next 5 years, do you think there will be inflation or deflation on average?"
label var QJH13a "What do you expect the average annual rate of inflation to be over the next 5 years? I expect the average annual rate of inflation to be ___ percent per year over the next 5 years."
label var QJH13b "What do you expect the average annual rate of deflation to be over the next 5 years? I expect the average annual rate of deflation to be ___ percent per year over the next 5 years."

label var QJH14 "Over the next 5 years, do you think that there will be an increase or decrease in GDP on average?"
label var QJH14a "What do you expect the average annual rate of increase in GDP will be over the next 5 years? increase to be ___ percent per year over the next 5 years."
label var QJH14b "What do you expect the average annual rate of decrease in GDP will be over the next 5 years? decrease to be ___ percent per year over the next 5 years."

label var QJH15 "In your view, will the total income of all members of your household (including you), after taxes and deductions, increase or decrease over the next 5 years on average?"
label var QJH15a "What do you expect the average annual rate of increase in the total income of all members of your household will be over the next 5 years?  ave annual increase ___ percent per year over the next 5 years."
label var QJH15b "What do you expect the average annual rate of decrease in the total income of all members of your household will be over the next 5 years?  ave annual decrease ___ percent per year over the next 5 years."

label var QJH16 "When do you expect that mortgage rates will start to rise in a significant way?"
label var QJH17_1 "How would you rate the credibility of the Federal Reserve in terms of its ability to achieve maximum employment and stable prices? - Rating"
label var QJH18_1 "What do you think is the chance that inflation will be more than 5% in the next 12 months? - Probability"

label var Q27 "Which fraction of your income do you invest?"
label var Q53 "What is your civil status?"
label var Q121 "What would you say is your political affiliation?"
label var Q54 "How many children do you have?"

label define lab_JH12 ///
	3 "Present prople with 1% question" ///
	4 "Present prople with 1% question" 
label values JH12 lab_JH12	   
label var JH12 "Randomize over what people see: 1% or 3% inflation in the Fed reaction"


*===============================================================================
*			construct variables: implied mean and uncertainty
*===============================================================================
foreach var in Q13_1 Q13_2  Q13_3 Q13_4 Q13_5 Q13_6  Q13_7 Q13_8 Q13_9 Q13_10 {
	destring `var', replace force
}
gen epi_12m_12plus= Q13_1 /* "What would you say is the percent chance that, over the next 12 months. . . - the rate of inflation will be 12% or higher" */
gen epi_12m_8_12= Q13_2 /* "What would you say is the percent chance that, over the next 12 months. . . - the rate of inflation will be between 8% and 12%" */
gen epi_12m_4_8= Q13_3 /* "What would you say is the percent chance that, over the next 12 months. . . - the rate of inflation will be between 4% and 8%" */
gen epi_12m_2_4= Q13_4 /* "What would you say is the percent chance that, over the next 12 months. . . - the rate of inflation will be between 2% and 4%" */
gen epi_12m_0_2=  Q13_5 /* "What would you say is the percent chance that, over the next 12 months. . . - the rate of inflation will be between 0% and 2%" */
gen epi_12m_m2_0= Q13_6 /* "What would you say is the percent chance that, over the next 12 months. . . - the rate of deflation (opposite of inflation) will be between 0% and 2%" */
gen epi_12m_m4_m2= Q13_7 /* "What would you say is the percent chance that, over the next 12 months. . . - the rate of deflation (opposite of inflation) will be between 2% and 4%" */
gen epi_12m_m8_m4= Q13_8 /* "What would you say is the percent chance that, over the next 12 months. . . - the rate of deflation (opposite of inflation) will be between 4% and 8%" */
gen epi_12m_m12_m8= Q13_9 /* "What would you say is the percent chance that, over the next 12 months. . . - the rate of deflation (opposite of inflation) will be between 8% and 12%" */
gen epi_12m_m12minus = Q13_10 /* "What would you say is the percent chance that, over the next 12 months. . . - the rate of deflation (opposite of inflation) will be 12% or higher" */


*generate average				
gen epi_12m_mean = 	epi_12m_12plus*14 + ///
					epi_12m_8_12*10 + ///
					epi_12m_4_8*6 + ///
					epi_12m_2_4*3 + ///
					epi_12m_0_2*1 + ///
					epi_12m_m2_0*(-1) + ///
					epi_12m_m4_m2*(-3) + ///
					epi_12m_m8_m4*(-6) + ///
					epi_12m_m12_m8*(-10) + ///
					epi_12m_m12minus*(-14)

replace epi_12m_mean=epi_12m_mean/100

*generate individual variance					
gen epi_12m_var	 =  epi_12m_12plus*(14-epi_12m_mean)^2 + ///
					epi_12m_8_12*(10-epi_12m_mean)^2 + ///
					epi_12m_4_8*(6-epi_12m_mean)^2 + ///
					epi_12m_2_4*(3-epi_12m_mean)^2 + ///
					epi_12m_0_2*(1-epi_12m_mean)^2 + ///
					epi_12m_m2_0*(-1-epi_12m_mean)^2 + ///
					epi_12m_m4_m2*(-3-epi_12m_mean)^2 + ///
					epi_12m_m8_m4*(-6-epi_12m_mean)^2 + ///
					epi_12m_m12_m8*(-10-epi_12m_mean)^2 + ///
					epi_12m_m12minus*(-14-epi_12m_mean)^2
										
replace epi_12m_var=epi_12m_var/100					

*generate individual sd
gen epi_12m_std=epi_12m_var^0.5


*===============================================================================
*			construct variables: point predictions
*===============================================================================
destring Q1342I, force replace
destring Q1342D, force replace
gen egdp_12m=.
replace egdp_12m=abs(Q1342I) if Q1341==2
replace egdp_12m=-abs(Q1342D) if Q1341==1
label var egdp_12m "Over the next 12 months, do you think that there will be an increase or decrease in GDP?"
replace egdp_12m=100 if egdp_12m>100 & egdp_12m~=.
replace egdp_12m=-100 if egdp_12m<-100 & egdp_12m~=.


destring QA12I, force replace
destring QA12D, force replace
gen edy_12m=.
replace edy_12m=abs(QA12I) if QA11==2
replace edy_12m=-abs(QA12D) if QA11==1
label var edy_12m "will the total income of all members of your household (including you), after taxes and deductions, increase or decrease over the next 12 months?"
replace edy_12m=100 if edy_12m>100 & edy_12m~=.
replace edy_12m=-100 if edy_12m<-100 & edy_12m~=.

destring Q112I, force replace
destring Q112D, force replace
gen epi_12m=.
replace epi_12m=abs(Q112I) if Q111==2
replace epi_12m=-abs(Q112D) if Q111==1
label var epi_12m "Over the next 12 months, do you think that there will be inflation or deflation?"
replace epi_12m=100 if epi_12m>100 & epi_12m~=.
replace epi_12m=-100 if epi_12m<-100 & epi_12m~=.

destring QJH14a, force replace
destring QJH14b, force replace
gen egdp_5y=.
replace egdp_5y=abs(QJH14a) if QJH14==2
replace egdp_5y=-abs(QJH14b) if QJH14==1
label var egdp_5y "Over the next 5 years, do you think that there will be an increase or decrease in GDP?"
replace egdp_5y=100 if egdp_5y>100 & egdp_5y~=.
replace egdp_5y=-100 if egdp_5y<-100 & egdp_5y~=.

destring QJH15a, force replace
destring QJH15b, force replace
gen edy_5y=.
replace edy_5y=abs(QJH15a) if QJH15==2
replace edy_5y=-abs(QJH15b) if QJH15==1
label var edy_5y "will the total income of all members of your household (including you), after taxes and deductions, increase or decrease over the next 5 years?"
replace edy_5y=100 if edy_5y>100 & edy_5y~=.
replace edy_5y=-100 if edy_5y<-100 & edy_5y~=.

destring QJH13a, force replace
destring QJH13b, force replace
gen epi_5y=.
replace epi_5y=abs(QJH13a) if QJH13==2
replace epi_5y=-abs(QJH13b) if QJH13==1
label var epi_5y "Over the next 5 years, do you think that there will be inflation or deflation?"
replace epi_5y=100 if epi_5y>100 & epi_5y~=.
replace epi_5y=-100 if epi_5y<-100 & epi_5y~=.

*===============================================================================
*		treatment variables
*===============================================================================

gen treatment_control=(JacksonHole=="TJH1")
gen treatment_IT=(JacksonHole=="TJH2")
gen treatment_AIT=(JacksonHole=="TJH3")
gen treatment_ITAIT=(JacksonHole=="TJH4")

gen treatmentN=1 if (JacksonHole=="TJH1")
replace treatmentN=2 if (JacksonHole=="TJH2")
replace treatmentN=3 if (JacksonHole=="TJH3")
replace treatmentN=4 if (JacksonHole=="TJH4")

*===============================================================================
*		clean variabes
*===============================================================================

*** zip code instead of age
destring Q1, force replace
replace Q1=. if Q1>100 & Q1~=.
rename Q1 age

*** sequential dates (Sept is 31 + day)
gen start_day1=start_day
replace start_day1=31+start_day if start_month==9

*** number of children
destring Q54, force replace
replace Q54=5 if Q54>5 & Q54~=.

gen N_children=Q54
gen male=(Q3==2)
gen Native_English=(Q2==3)
gen educ=Q48
gen income=Q49
gen nonwhite=1-(Q51==15 | Q51==14 | Q51==16)
gen hispanic=(Q52==2)
gen married=(Q53==2)
gen single=(Q53==5)

gen party_democrat=(Q121==1)
gen party_republican=(Q121==4)
gen party_other=(Q121==3)

destring QJH17_1 , force replace
destring QJH11, force replace
replace QJH11=. if QJH11>=100

destring QJH123, force replace 
replace QJH123=. if QJH123>=100

destring QJH124, force replace
replace QJH124=. if QJH124>=100

cd "C:\Dropbox\Average_target_survey\replication_folder\workfiles"

compress
save step003, replace






